﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mbr.Reviews.Core.Contracts;
using Mbr.Reviews.Core.Contracts.DTO;

namespace Mbr.Reviews.Core.ProductCrawlers
{
    public class InMemoryProductCrawler : ICrawlForProducts
    {
        private readonly IStoreProducts store;
        private readonly List<Contracts.DTO.Product> products = new List<Contracts.DTO.Product>(new Contracts.DTO.Product[] { 
            new Contracts.DTO.Product
            {
                Id = "1",
                Name = "Nokia Lumia 900",
                Uri = new Uri("http://www.google.com"),
                Description = "Nokia Lumia 900 Smartphone",
                Tags = new string[]{}
            },
            new Contracts.DTO.Product
            {
                Id = "2",
                Name = "Samsung Galaxy Tab",
                Uri = new Uri("http://www.google.com"),
                Description = "Samsung Galaxy Tab Tablet with Android",
                Tags = new string[]{}
            },
            new Contracts.DTO.Product
            {
                Id = "3",
                Name = "Samsung Galaxy S3",
                Uri = new Uri("http://www.google.com"),
                Description = "The Samsung Galaxy S3 Smartphone",
                Tags = new string[]{}
            },
            new Contracts.DTO.Product
            {
                Id = "4",
                Name = "HTC Windows Phone 8X",
                Uri = new Uri("http://www.google.com"),
                Description = "The best Windows 8 Smartphone yet. From HTC.",
                Tags = new string[]{}
            }
        });

        public InMemoryProductCrawler(IStoreProducts store)
        {
            this.store = store;
        }

        public void BeginCrawl(params string[] keywords)
        {
            foreach (var product in products)
            {
                if (!product.IsMatch(keywords))
                {
                    continue;
                }

                store.Store(product);
            }
        }
    }
}
